package com.gx.smart.building.ui.swap

import android.app.Activity
import android.content.Intent
import android.view.ViewGroup
import com.blankj.utilcode.util.ToastUtils
import com.gx.smart.base.BaseMVVMActivityV2
import com.gx.smart.building.R
import com.gx.smart.building.databinding.ActivitySignatureBinding
import com.gx.smart.building.ui.common.util.ImageSaveUtil
import com.gx.smart.building.ui.swap.viewmodel.SignatureViewModel

class SignatureActivity : BaseMVVMActivityV2<SignatureViewModel>() {

    private lateinit var viewBinding: ActivitySignatureBinding
    override fun onBindViewModel(): Class<SignatureViewModel> = SignatureViewModel::class.java

    override fun onBindLayout(): Int = R.layout.activity_signature

    override fun getToolbarTitle(): String = "手写签名"

    override fun initContentView(root: ViewGroup) {
        viewBinding = ActivitySignatureBinding.inflate(layoutInflater, root, true)
        viewBinding.repeat.setOnClickListener {
            viewBinding.signatureView.clearCanvas()
        }
        viewBinding.confirm.setOnClickListener {
            if (viewBinding.signatureView.isBitmapEmpty) {
                ToastUtils.showLong("请手写签名!")
                return@setOnClickListener
            }
            val bitmap = viewBinding.signatureView.signatureBitmap
            val uri = ImageSaveUtil.saveBitmap(bitmap, this)
            val intent = Intent()
            intent.putExtra("uri", uri)
            setResult(Activity.RESULT_OK, intent)
            finish()
        }
    }
}